We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392949 - OMF output: Far call to label in a different section (in a group and not first section in it) but same file encodes wrong destination
Summary: OMF output: Far call to label in a different section (in a group and not firs...
Status: CLOSED FIXED
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.16.xx
Hardware: All All
: Medium major
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2025-08-30 14:24 PDT by E. C. Masloch
Modified: 2025-09-03 10:23 PDT (History)
5 users (show)

Obtained from: Built from git using configure
Generated by: Human
Bug category: Incorrect main output, Invalid main output, Unexpected or confusing behavior
Observed for: Production code
Regression: Yes (specify version below)
Regression since:
NASM version 2.14.03rc2 compiled on Aug 31 2019


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2025-08-30 14:24:10 PDT
This bug appears to be fixed by v2.17 development versions as of https://github.com/netwide-assembler/nasm/commit/9ea92eab6e26b5527e2dc72424a886a1a4061a48 (This revision is the ~/proj/nasm/nasm file in the test log.)

I found that calling far as in "call far label" (but probably also an explicit "call seg label:label") fails to encode the expected address if:

 - The call and the label are in the same assembly input stream / object file.
 - The label is in a different section than the call.
 - The label section is in a group, and there is a different section in the same group.
 - The label section is physically to be placed not as the first section in its group.

This bug cropped up during updating of my lDOS kernel. I ended up working around it by placing the label into a different assembly source file / object file, albeit I would have preferred to keep it in the same file: https://hg.pushbx.org/ecm/msdos4/rev/693592bf0802

test1.exe has the wrong address of the far call with the NASM v2.16 revision. test23.exe is correct for both NASM versions.

The used WarpLink is renamed to warplink.exe from wl.exe in https://pushbx.org/ecm/download/old/warplink/20250829.zip

The script is used to run WarpLink in dosemu2, and is available here https://hg.pushbx.org/ecm/msdos4/file/494fe588a5a8/warplink.sh


test$ cat test1.asm

section DOSENTRY class=DOSENTRY
..start:
        call far label
        mov ax, 4C00h
        int 21h

section SYSINITSEG class=SYSINIT align=16
        times 256 int3

section SYSINITTRAIL class=SYSINIT
group SYSINITGROUP SYSINITSEG SYSINITTRAIL
        times 256 int3

label:
        retf

        times 256 int3

section MZEXESTACK stack class=STACK align=16
        resb 512
test$ cat test2.asm

section DOSENTRY class=DOSENTRY

 extern label
..start:
        call far label
        mov ax, 4C00h
        int 21h

section SYSINITSEG class=SYSINIT align=16
section SYSINITTRAIL class=SYSINIT
group SYSINITGROUP SYSINITSEG SYSINITTRAIL
test$ cat test3.asm
section SYSINITSEG class=SYSINIT align=16
        times 256 int3

section SYSINITTRAIL class=SYSINIT
group SYSINITGROUP SYSINITSEG SYSINITTRAIL
        times 256 int3

 global label
label:
        retf

        times 256 int3

section MZEXESTACK stack class=STACK align=16
        resb 512
test$ nasm test1.asm -fobj && ~/proj/msdos4.hg/hg/warplink.sh /mx test1.obj,test1.exe,test1.map\; && dos ldebug\ test1.exe
dosemu -dumb -td -kt -q -quiet -K /home/evln/wwwecm/test/20250830 -E warplink  /mx test1.obj,test1.exe,test1.map;
About to Execute : warplink  /mx test1.obj,test1.exe,test1.map;

WarpLink release 2 by ecm (2025 August), Michael Devore (1989-1993).
Public Domain software, all copyrights surrendered.


EXE load image size: 002K
About to Execute : ldebug test1.exe
lDebug (2025-03-09)
-r
AX=0000 BX=0000 CX=0311 DX=0000 SP=0200 BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2B47 IP=0000 NV UP EI PL ZR NA PE NC
2B47:0000 9A0002482C        call    2C48:0200
-t
AX=0000 BX=0000 CX=0311 DX=0000 SP=01FC BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2C48 IP=0200 NV UP EI PL ZR NA PE NC
2C48:0200 DC38              fdivr   double [bx+si]                   DS:0000=CD
-q
test$ nasm test2.asm -fobj && nasm test3.asm -fobj && ~/proj/msdos4.hg/hg/warplink.sh /mx test2.obj+test3.obj,test23.exe,test23.map\; && dos ldebug\ test23.exe
dosemu -dumb -td -kt -q -quiet -K /home/evln/wwwecm/test/20250830 -E warplink  /mx test2.obj+test3.obj,test23.exe,test23.map;
About to Execute : warplink  /mx test2.obj+test3.obj,test23.exe,test23.map;

WarpLink release 2 by ecm (2025 August), Michael Devore (1989-1993).
Public Domain software, all copyrights surrendered.


EXE load image size: 002K
About to Execute : ldebug test23.exe
lDebug (2025-03-09)
-r
AX=0000 BX=0000 CX=0311 DX=0000 SP=0200 BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2B47 IP=0000 NV UP EI PL ZR NA PE NC
2B47:0000 9A0002482B        call    2B48:0200
-t
AX=0000 BX=0000 CX=0311 DX=0000 SP=01FC BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2B48 IP=0200 NV UP EI PL ZR NA PE NC
2B48:0200 CB                retf
-q
test$ nasm -v
NASM version 2.16.02rc2 compiled on Oct 12 2023
test$ ~/proj/nasm/nasm test1.asm -fobj && ~/proj/msdos4.hg/hg/warplink.sh /mx test1.obj,test1.exe,test1.map\; && dos ldebug\ test1.exe
dosemu -dumb -td -kt -q -quiet -K /home/evln/wwwecm/test/20250830 -E warplink  /mx test1.obj,test1.exe,test1.map;
About to Execute : warplink  /mx test1.obj,test1.exe,test1.map;

WarpLink release 2 by ecm (2025 August), Michael Devore (1989-1993).
Public Domain software, all copyrights surrendered.


EXE load image size: 002K
About to Execute : ldebug test1.exe
lDebug (2025-03-09)
-r
AX=0000 BX=0000 CX=0311 DX=0000 SP=0200 BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2B47 IP=0000 NV UP EI PL ZR NA PE NC
2B47:0000 9A0002482B        call    2B48:0200
-t
AX=0000 BX=0000 CX=0311 DX=0000 SP=01FC BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2B48 IP=0200 NV UP EI PL ZR NA PE NC
2B48:0200 CB                retf
-q
test$ ~/proj/nasm/nasm test2.asm -fobj && ~/proj/nasm/nasm test3.asm -fobj && ~/proj/msdos4.hg/hg/warplink.sh /mx test2.obj+test3.obj,test23.exe,test23.map\; && dos ldebug\ test23.exe
dosemu -dumb -td -kt -q -quiet -K /home/evln/wwwecm/test/20250830 -E warplink  /mx test2.obj+test3.obj,test23.exe,test23.map;
About to Execute : warplink  /mx test2.obj+test3.obj,test23.exe,test23.map;

WarpLink release 2 by ecm (2025 August), Michael Devore (1989-1993).
Public Domain software, all copyrights surrendered.


EXE load image size: 002K
About to Execute : ldebug test23.exe
lDebug (2025-03-09)
-r
AX=0000 BX=0000 CX=0311 DX=0000 SP=0200 BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2B47 IP=0000 NV UP EI PL ZR NA PE NC
2B47:0000 9A0002482B        call    2B48:0200
-t
AX=0000 BX=0000 CX=0311 DX=0000 SP=01FC BP=0000 SI=0000 DI=0000
DS=2B37 ES=2B37 SS=2B79 CS=2B48 IP=0200 NV UP EI PL ZR NA PE NC
2B48:0200 CB                retf
-q
test$ ~/proj/nasm/nasm -v
NASM version 2.17rc0 compiled on Aug 28 2025
test$
Comment 2 E. C. Masloch 2025-08-30 14:42:59 PDT
This bug was a regression. At least with my old NASM version from 2019 it works as expected:

$ oldnasm -v
NASM version 2.14.03rc2 compiled on Aug 31 2019
Comment 3 E. C. Masloch 2025-08-30 14:53:30 PDT
Introduced by 2022-12-07 commit in https://github.com/netwide-assembler/nasm/commit/cab5b75145466232cd6a8cfed46adc4b9d0483d8
Comment 4 E. C. Masloch 2025-09-03 10:23:16 PDT
The fix for this apparently caused https://bugzilla.nasm.us/show_bug.cgi?id=3392950